<!--pages/traffic/goPay.wxml-->
<template>
  <view>
    <view class="page">
      <!-- <image src="../../image/bg.jpg" class="bg" /> -->
      <view class="bg"></view>
      <view class="top-title" :style="{height:customBar+'px',paddingTop:statusBar+'px'}">
        <navigator
          :url="'../home/home?parkingCode='+parkingCode"
          open-type="redirect"
          hover-class="none"
          class="top-title-back"
        >
          <image src="../../image/back2.png" style="margin-top:6rpx"/>
        </navigator>
        <text class="top-title-t1" style="text-align:left">停车费用缴纳</text>
      </view>
      <view class="coupon" v-if="couponInfos">
        <image src="../../image/counpon.png" />
        <view class="coupon-content">
          <view class="p1">
            建业车生活送你一张<text>{{couponInfos.deduction}}元</text>优惠券
          </view>
          <view class="p1" style="font-size: 28rpx;font-weight: 500;">临停车优惠券</view>
          <view class="p2">满{{couponInfos.useStartPrice}}元可用</view>
          <view
            class="p2"
            v-if="couponInfos.validType==1"
          >{{couponInfos.validStartDay}}~{{couponInfos.validEndDay}}</view>
        </view>
        <view class="coupon-btn" @tap="receivecoupon(couponInfos.id)" v-if="!isReceive">立即领取</view>
        <view class="coupon-btn" style="background:#EFEFEF;color:#909090" v-else>已领取</view>
      </view>
      <view v-else style="height:330rpx"></view>
      <view class="page-box">
        <view class="box">
          <view class="plate">{{carInfos.carNo}}</view>
          <view class="title">{{carInfos.parkName}}</view>
          <view class="intime">{{carInfos.inTime}} 入场</view>
          <!--临停-->
          <view class="info-list">
            <view class="item">
              <view class="box-time-p1">停车时长</view>
              <view class="box-time-p2">{{carInfos.parlLong}}</view>
            </view>
            <view class="item">
              <view class="box-time-p1">停车费</view>
              <view class="box-time-p2">{{carInfos.actualAmount}}元</view>
            </view>
            <view class="item" @tap="goCoupon">

              <view class="box-time-p1">优惠金额</view>
              <view class="box-time-coupon" v-if="couponNum">{{couponNum}}张优惠券可用</view>
              <view class="box-time-coupon" v-if="couponNum==0&&mobile!==''">暂无优惠券可用</view>
              <view class="box-time-coupon" v-if="mobile==''">点击授权，查看优惠券</view>
              <view class="box-time-p2">
                {{discountAmount}}元
                <text style="color:#409DFE">></text>
              </view>
            </view>
            <view class="item">
              <view class="box-time-p1">需缴费</view>
              <view class="box-time-p2">{{payAmount}}元</view>
            </view>
          </view>
        </view>

      </view>
      <view class="btn" @tap="goPay" v-if="payAmount>0">立即支付</view>
      <view class="btn" @tap="goPayZero" v-else>确定出场</view>
    </view>
    <view v-if="isOutTime">
      <view class="panel-black"></view>
      <view class="panel-box">
        <view class="panel-box-t1">提示</view>
        <view class="panel-box-t2">支付超时，请重新查询</view>
        <view class="panel-box-btn" @tap="sureInit">确定</view>
      </view>
    </view>
    <view v-if="isError">
      <view class="panel-black"></view>
      <view class="panel-box">
        <view class="panel-box-t1">提示</view>
        <view class="panel-box-t2">{{errorMsg}}</view>
        <view class="panel-box-btn" @tap="sureBack">确定</view>
      </view>
    </view>
    <view v-if="!hasPhone">
      <view class="panel-black"></view>
      <view class="panel-box">
        <image src="../../image/close.png" class="panel-box-close" @tap="hasPhone=true"/>
        <view class="panel-box-t1">提示</view>
        <view class="panel-box-t2">点击授权，获取可用优惠券</view>
        <button
          openType="getPhoneNumber"
          @GetPhoneNumber="onGetPhoneNumber"
          class="panel-box-btn"
          style="height:100rpx"
        >获取手机号</button>
      </view>
    </view>
  </view>
</template>
<script>
import Taro from "@tarojs/taro";
import "./goPay.less";
import { setGlobalData, getGlobalData } from "../../globalData.js";

import bulterApi from "@souche2014/bulter-api";
const api = bulterApi({ partner: "IOParking" });
export default {
  data() {
    return {
      isCounpon: true,
      isChannle: "1", //是否是场内支付，1：通道支付, 0：场内支付
      mobile:"",
      isOutTime: false,
      seconds: 305,//倒计时5分钟
      startTime:Date.now(),
      endTime:Date.now()+5*60*1000,//倒计时解决息屏问题
      hasPhone: true,
      carNo: "", //车牌号
      carType: 0, //车类型 1：月租 2：储值 3：临停
      parkId: 0, //车场id
      discountAmount: 0, //选择优惠券后的折扣金额
      payAmount: 0, //实际支付金额  总金额-抵扣的金额（优惠券）
      couponId: 0, //优惠券ID
      couponIssuingUnit:'',//优惠券发放单位
      couponParkId: 0,
      parkingCode: "",
      channelCode: "",
      errorMsg: "",
      carInfos: {
        parkName: "",
        carNo: "",
        inTime: "",
        parlLong: "",
        actualAmount: ""
      },
      isError: false,
      coupon: 0,
      isCoupon: false,
      codeType: "1", //1:场内，2：通道，3：无牌车
      couponInfos: null,
      isReceive: false,
      statusBar: 0,//状态栏高度
      customBar:0,//胶囊按钮高度
      couponNum:0,//可用优惠券数量
      apiBaseUrl: process.env.IOParking.API_HOST //请求头
    };
  },
  mounted(){
    Taro.getSystemInfo({
      success:(res)=> {
        this.statusBar = res.statusBarHeight; //状态栏高度
        let custom = Taro.getMenuButtonBoundingClientRect(); //菜单按钮
        this.customBar = custom.height+8;
        console.log(this.statusBar,this.customBar);
      }
    });
  },
  onLoad: function(options) {
    console.log("页面参数", options);
    console.log("Time:",this.startTime)
    var that = this;
    if (options.channelCode || options.parkingCode || options.carNo) {
      //体验开发版本扫码获得参数
      console.log("体验扫码参数:", options);
      that.parkingCode = options.parkingCode ? options.parkingCode : "";
      that.channelCode = options.channelCode ? options.channelCode : "";
      that.carNo = options.carNo ? options.carNo : "";
    } else if (options.q) {
      //正式版扫码获得参数
      let qrUrl = decodeURIComponent(options.q);
      that.parkingCode = that.getQueryString(qrUrl, "parkingCode");
      that.channelCode = that.getQueryString(qrUrl, "channelCode");
      console.log(
        "正式扫码parkingCode，channelCode:",
        that.parkingCode,
        that.channelCode
      );
    }
    that.discountAmount = options.discountAmount ? options.discountAmount : 0;
    that.couponId = options.id ? options.id : "";
    that.couponIssuingUnit=options.couponIssuingUnit?options.couponIssuingUnit:'';
    that.mobile=getGlobalData("mobile")?getGlobalData("mobile"):"";
    if (that.channelCode !== "") {
      //通道扫码
      if (getGlobalData("openId")) {
        that.channelData();
      } else {
        that.wx_login();
      }
      that.codeType = "2";
      console.log("通道扫码进入", options);
    } else {
      //场内扫码或者小程序直接进去
      if (getGlobalData("openId")) {
        that.parkingData();
      } else {
        that.wx_login();
      }
      that.codeType = "1";
    }
  },
  methods: {
    wx_login() {
      api
        .getUserInfo({
          scope: "all"
        })
        .then(resp => {
          if (resp.success) {
            console.log("authCode is：", resp.data);
            if (resp.data == "mock") {
              setGlobalData("openId", "oRPxj5ZrsZGRuxTa-UrzEBeLuv-s");
              //setGlobalData("mobile", "17761643218");
              this.initData();
              this.unexpiredData()
              return;
            }
            this.getInfos(resp.data);
          } else {
            console.log("err is ", resp.message, "err code is ", resp.code);
          }
        });
    },
    getInfos(authCode) {
      let that = this;
      Taro.request({
        url: this.apiBaseUrl + "/weixin/souchegetuser?authCode=" + authCode,
        data: {},
        header: {
          "content-type": "application/json" // 默认值
        },
        method: "GET",
        success(res) {
          console.log(res.data);
          if (res.data.isSuccess) {
            var userOpenId = res.data.data.openId;
            setGlobalData("openId", userOpenId);
            setGlobalData("mobile", res.data.data.phoneNum);
            that.mobile=getGlobalData("mobile")?getGlobalData("mobile"):"";
            that.initData();
            if(that.mobile!==''){
              that.unexpiredData()
            }
            api.bury("userAuthorizationNum", {
              parkName:that.carInfos.parkName?that.carInfos.parkName:'',
              parkId:that.carInfos.parkId?that.carInfos.parkId:'',
              time: new Date().valueOf(),
              mobile:getGlobalData("mobile")?getGlobalData("mobile"):""
            });
          }
        }
      });
    },
    onGetPhoneNumber({ detail }) {
        const { encryptedData, iv } = detail;
        console.log("phone打印:" + JSON.stringify(detail));
        if (encryptedData && iv) {
          this.authPhone(encryptedData, iv);
          this.hasPhone=true
          Taro.showLoading({
              title: "授权中，请稍后",
              mask: true
            });
        }
    },
    authPhone(encryptedData,iv) {
      api.register({
              encryptedData: encryptedData,
              iv: iv,
              scope: "all"
          })
          .then(resp => {
              Taro.hideLoading();
              if (resp.success) {
                  console.log("用户注册 ", resp.data);
                  if(resp.data=='mock'){
                      //setGlobalData("mobile", '17761643218');
                        this.mobile=getGlobalData("mobile")?getGlobalData("mobile"):"";
                      return
                  }
                  this.getInfos(resp.data)
              } else {
                  console.log("err is ", resp.msg, "err code is ", resp.code);
              }
          })
          .catch(e => {
              console.log(e);
          });
    },
    initData() {
      // if (this.discountAmount < this.carInfos.actualAmount) {
      //   this.discountAmount = this.carInfos.actualAmount;
      // }
      if (this.channelCode !== "") {
        //通道扫码
        this.channelData();
        this.codeType = "2";
      } else {
        //场内扫码或者小程序直接进去
        this.parkingData();
        this.codeType = "1";
      }
    },
    //通道扫码车辆信息查询
    channelData() {
      Taro.showLoading({
        title: "加载中",
        mask: true
      });
      var that = this;
      var base = this.apiBaseUrl;
      let aa = {
        mobile: getGlobalData("mobile"),
        wxOpenId: getGlobalData("openId"),
        carNo: that.carNo,
        parkingCode: that.parkingCode,
        channelCode: that.channelCode
      };
      console.log(aa);
      Taro.request({
        url: base + "/parkingpayment/getchannelparkorderinfo",
        data: {
          mobile: getGlobalData("mobile"),
          wxOpenId: getGlobalData("openId"),
          carNo: that.carNo,
          parkingCode: that.parkingCode,
          channelCode: that.channelCode
        },
        header: {
          "content-type": "application/json" // 默认值
        },
        method: "POST",
        success(res) {
          Taro.hideLoading();
          console.log("通道扫码", res.data.data);
          if (res.data.isSuccess) {
            that.seconds = 305;
            that.startTime=new Date(res.data.data.outTime).valueOf()//出场时间为开始，5分钟后生效
            that.endTime=that.startTime+5*60*1000
            that.setTimeCount(); //页面失效倒计时
            that.carInfos = res.data.data;
            that.parkId = res.data.data.parkId;
            if(that.carInfos.carNo&&that.carInfos.carNo.indexOf('虚')!= -1){//无牌车显示
                that.carInfos.carNo='无牌车'
            }
            that.getcoupon();
            //进入优惠券页面选择后
            that.payAmount = that.minus(
              that.carInfos.actualAmount,
              that.discountAmount
            );
            console.log(that.payAmount);
            if (that.payAmount < 0) {
              that.payAmount = 0;
            }
            if (that.discountAmount > that.carInfos.actualAmount) {
              that.discountAmount = that.carInfos.actualAmount;
            }
            if(getGlobalData("mobile")!==''||getGlobalData("mobile")){
              that.unexpiredData();
            }
           api.bury("scanChannelNum", {
              parkId:that.parkId,
              parkName:that.carInfos.parkName,
              channelCode: that.channelCode,
              plateNo:that.carInfos.carNo,
              scanType:'通道码',
              payType:'微信',
              inTime:that.carInfos.inTime,
              scanTime: new Date().valueOf(),
           });
          } else {
            that.isError = true;
            that.errorMsg = res.data.message;
          }
        }
      });
    },
    //场内码车辆信息查询
    parkingData() {
      Taro.showLoading({
        title: "加载中",
        mask: true
      });
      var that = this;
      var base = this.apiBaseUrl;
      console.log("场内码读取的信息：", {
        mobile: getGlobalData("mobile") || "",
        wxOpenId: getGlobalData("openId")
      });
      Taro.request({
        url: base + "/parkingpayment/getpreparkorderinfo",
        data: {
          mobile: getGlobalData("mobile"),
          wxOpenId: getGlobalData("openId"),
          carNo: that.carNo,
          parkingCode: that.parkingCode,
          channelCode: that.channelCode
        },
        header: {
          "content-type": "application/json" // 默认值
        },
        method: "POST",
        success(res) {
          Taro.hideLoading();
          console.log("场内页面进入", res.data);

          if (res.data.isSuccess) {
            that.seconds = 305;
            that.startTime=new Date(res.data.data.outTime).valueOf()//出场时间为开始，5分钟后生效
            that.endTime=that.startTime+5*60*1000
            console.log("当前时间戳",that.startTime,that.endTime)
            that.setTimeCount(); //页面失效倒计时
            that.carInfos = res.data.data;
            that.parkId = res.data.data.parkId;
            that.getcoupon();
            //进入优惠券页面选择后
            that.payAmount = that.minus(
              that.carInfos.actualAmount,
              that.discountAmount
            );
            console.log("实际缴费", that.payAmount);
            if (that.payAmount < 0) {
              that.payAmount = 0;
            }
            if (that.discountAmount > that.carInfos.actualAmount) {
              that.discountAmount = that.carInfos.actualAmount;
            }
            if(getGlobalData("mobile")!==''||getGlobalData("mobile")){
              that.unexpiredData();
            }
            if(that.parkingCode!==''){
                api.bury("scanInFiledNum", {
                parkId:that.parkId,
                parkName:that.carInfos.parkName,
                parkingCode: that.parkingCode,
                plateNo:that.carInfos.carNo,
                scanType:"场内码",
                payType:'微信',
                inTime:that.carInfos.inTime,
                scanTime: new Date().valueOf(),
            });
            }
            
          } else {
            that.isError = true;
            that.errorMsg = res.data.message;
          }
        }
      });
    },
    getcoupon() {
      var that = this;
      var base = that.apiBaseUrl;
      that.setDataloading = true;
      Taro.request({
        url: base + "/carcoupon/alllist",
        data: {
          pubPlace: 1, //1：缴费页，2：支付完成页
          parkId: that.parkId
        },
        header: {
          "content-type": "application/json" // 默认值
        },
        method: "POST",
        success(res) {
          console.log(res.data.data);
          if (res.data.isSuccess) {
            that.couponInfos = res.data.data;
            if (res.data.data) {
              that.couponParkId = res.data.data.parkId;
            }
          }
        }
      });
    },
    receivecoupon(couponId) {
      var that = this;
      if (getGlobalData("mobile") == "") {
        that.hasPhone = false;
        return;
      }
      // console.log(that.handleCoupon(that.couponInfos));
      // if (that.handleCoupon(that.couponInfos) == 0) {
      //   return;
      // }
      var base = that.apiBaseUrl;
      Taro.request({
        url: base + "/carcoupon/receivecoupon",
        data: {
          mobile: getGlobalData("mobile"),
          wxOpenId: getGlobalData("openId"),
          couponId: couponId,
          parkId: that.couponParkId
        },
        header: {
          "content-type": "application/json" // 默认值
        },
        method: "POST",
        success(res) {
          console.log(res.data.data);
          if (res.data.isSuccess) {
            Taro.showToast({
              title: "领取成功",
              icon: "success",
              duration: 600,
              mask: true
            });
            that.isReceive = true;
            // that.discountAmount=that.couponInfos.deduction
            // that.payAmount = that.minus(
            //   that.carInfos.actualAmount,
            //   that.couponInfos.deduction
            // );
            // if (that.payAmount < 0) {
            //   that.payAmount = 0;
            // }
          } else {
            Taro.showToast({
              title: res.data.message,
              icon: "none",
              duration: 800,
              mask: true
            });
          }
        }
      });
    },
    goPayZero() {
      Taro.showLoading({
        title: "加载中",
        mask: true
      });
      var that = this;
      Taro.login({
        success: function(res) {
          if (res.code) {
            //发起网络请求
            Taro.request({
              url: that.apiBaseUrl + "/parkingpayment/zeroorderpay", //你需要给后台传一个code
              method: "POST",
              data: {
                amount: +that.carInfos.actualAmount, //总金额
                payAmount: that.payAmount, //总金额-抵扣的金额（优惠券）=实际金额
                discountAmount: +that.discountAmount || 0,
                couponId: +that.couponId,
                couponIssuingUnit:that.couponIssuingUnit,
                carNo: that.carInfos.carNo,
                parkId: that.carInfos.parkId || 0,
                mobile: getGlobalData("mobile"),
                wxOpenId: getGlobalData("openId"),
                parlLong: that.carInfos.parlLong || "",
                startTime: that.carInfos.inTime || "",
                endTime: that.carInfos.outTime || "",
                orderNo: that.carInfos.orderNo || "",
                payType: that.codeType
              },
              success: function(res) {
                // 成功后  后台返回参数  timeStamp,nonceStr,package,paySign,appid。(有的还会返回其他参数，左边的这几个参数是必须返回的)
                console.log(res.data);
                Taro.hideLoading();
                if (res.data.isSuccess) {
                  let scanType=''
                  if(that.codeType=='2'){
                    scanType='通道扫码'
                  }else if(that.codeType=='1'){
                    scanType='场内扫码'
                  }else{
                    scanType='未扫码'
                  }
                  api.bury("temporaryFreeNum", {
                    parkId:that.parkId,
                    parkName:that.carInfos.parkName,
                    channelCode: that.channelCode,
                    plateNo:that.carInfos.carNo,
                    scanType:scanType,
                    payType:'微信',
                    inTime:that.carInfos.inTime,
                    payTime: new Date().valueOf(),
                  });
                  Taro.redirectTo({
                    url: "../trafficManage/paySuccess?parkId=" + that.parkId
                  });
                } else {
                  Taro.showToast({
                    title: "下单失败",
                    icon: "error",
                    duration: 1000,
                    mask: true
                  });
                }
              },
              fail: function(err) {
                console.log(err);
              }
            });
          } else {
            console.log("获取用户登录态失败！" + res.errMsg);
          }
        }
      });
    },
    goPay() {
      Taro.showLoading({
        title: "正在下单中",
        mask: true
      });
      var that = this;
      Taro.login({
        success: function(res) {
          if (res.code) {
            //发起网络请求
            Taro.request({
              url: that.apiBaseUrl + "/parkingpayment/preparkorderpay", //你需要给后台传一个code
              method: "POST",
              data: {
                amount: +that.carInfos.actualAmount, //总金额
                payAmount: that.payAmount, //总金额-抵扣的金额（优惠券）=实际金额
                discountAmount: +that.discountAmount || 0,
                couponIssuingUnit:that.couponIssuingUnit,
                couponId: +that.couponId,
                carNo: that.carInfos.carNo,
                parkId: that.carInfos.parkId || 0,
                mobile: getGlobalData("mobile"),
                wxOpenId: getGlobalData("openId"),
                parlLong: that.carInfos.parlLong || "",
                startTime: that.carInfos.inTime || "",
                endTime: that.carInfos.outTime || "",
                orderNo: that.carInfos.orderNo || "",
                payType: that.codeType
              },
              success: function(res) {
                // 成功后  后台返回参数  timeStamp,nonceStr,package,paySign,appid。(有的还会返回其他参数，左边的这几个参数是必须返回的)
                console.log(res.data);
                Taro.hideLoading();
                if (res.data.isSuccess) {
                  var orderId = res.data.data.chargeOrderId;
                  that.wxPay(res.data.data.wxPayOrderParams, orderId);
                } else {
                  Taro.showToast({
                    title: "下单失败",
                    icon: "error",
                    duration: 1000,
                    mask: true
                  });
                }
              },
              fail: function(err) {
                console.log(err);
              }
            });
          } else {
            console.log("获取用户登录态失败！" + res.errMsg);
          }
        }
      });
    },
    wxPay(obj, orderId) {
      //微信支付
      var that = this;
      Taro.requestPayment({
        timeStamp: obj.timeStamp,
        nonceStr: obj.nonceStr,
        package: obj.package,
        signType: obj.signType,
        paySign: obj.paySign,
        success(res) {
          console.log("支付成功");
          let scanType=''
          if(that.codeType=='2'){
            scanType='通道扫码'
          }else if(that.codeType=='1'){
            scanType='场内扫码'
          }else{
            scanType='未扫码'
          }
          api.bury("temporaryNum", {
            parkId:that.parkId,
            parkName:that.carInfos.parkName,
            channelCode: that.channelCode,
            plateNo:that.carInfos.carNo,
            scanType:scanType,
            payType:'微信',
            inTime:that.carInfos.inTime,
            payTime: new Date().valueOf(),
          });
          Taro.redirectTo({
            url: "../trafficManage/paySuccess?parkId=" + that.parkId
          });
        },
        fail(res) {
          Taro.showToast({
            title: "取消支付",
            icon: "error",
            duration: 1000,
            mask: true
          });
          that.couponId=0
          that.couponIssuingUnit=''
          that.discountAmount=0
          if (that.channelCode !== "") {
                that.channelData();
            } else {
              that.parkingData();
            }
          console.log(res);
        }
      });
    },
    unexpiredData: function() {
      var that = this;
      var base = that.apiBaseUrl;
      Taro.request({
        url: base + "/carcoupon/couponlist",
        data: {
            mobile: getGlobalData("mobile") || "",
            wxOpenId: getGlobalData("openId"),
            parkId: that.parkId,
            amount:that.carInfos.actualAmount
        },
        header: {
          "content-type": "application/json" // 默认值
        },
        method: "POST",
        success(res) {
          if (res.data.isSuccess) {
              that.couponNum = res.data.data.length;
              console.log("获得手机号的优惠券数量：",that.couponNum)
          }
        }
      });
    },
    goBack() {
      Taro.reLaunch({
        url: "../home/home"
      });
    },
    goCoupon() {
      console.log(getGlobalData("mobile"));
      //this.isCoupon=true
      if (getGlobalData("mobile") == ""||!getGlobalData("mobile")) {
        this.hasPhone = false;
        return;
      }
      Taro.navigateTo({
        url:
          "../counpon/counponList?parkId=" +
          this.parkId +
          "&carNo=" +
          this.carNo +
          "&parkingCode=" +
          this.parkingCode +
          "&channelCode=" +
          this.channelCode +
          "&money=" +
          this.carInfos.actualAmount+'&orderNo='+this.carInfos.orderNo
      });
    },
    sureInit() {
      this.isOutTime = false;
      this.getcoupon();
      if (this.channelCode !== "") {
        if (getGlobalData("openId")) {
          this.channelData();
        } else {
          this.wx_login();
        }
      } else {
        this.parkingData();
      }
    },
    num(a) {
      if (a != null && a.toString() != "") {
        let r = /^-?(0|[1-9]+\d*|[1-9]+\d*\.\d+|0\.\d+)$/;
        if (r.test(a.toString())) {
          return true;
        }
      }
      return false;
    },
    //减法
    minus(a, b) {
      if (!this.num(a) || !this.num(b)) {
        return null;
      }
      let c, d, m, n;
      try {
        c = a.toString().split(".")[1].length;
      } catch (e) {
        c = 0;
      }
      try {
        d = b.toString().split(".")[1].length;
      } catch (e) {
        d = 0;
      }
      m = Math.pow(10, Math.max(c, d));
      return (a * m - b * m) / m;
    },
    sureBack() {
      Taro.reLaunch({
        url: "../home/home"
      });
    },
    setTimeCount() {
      if (this.seconds > 0) {
        this.seconds = this.seconds - 1;
        let str = Date.now();
        if(str > this.endTime){//超过了当前5分钟'
            console.log("超过5分钟",str)
            this.isOutTime = true;
            this.seconds=0
          }else{//没有超过了当前5分钟'
              setTimeout(this.setTimeCount, 1000);
          }
      } else {
        console.log("五分钟")
        this.seconds = 0;
        this.isOutTime = true;
      }
    },
    //解析链接方法
    getQueryString(url, name) {
      var reg = new RegExp("(^|&|/?)" + name + "=([^&|/?]*)(&|/?|$)", "i");
      var r = url.substr(1).match(reg);
      if (r != null) {
        return r[2];
      }
      return null;
    }
  }
};
</script>
